<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="招商加盟">

    <!--suppress ALL -->
  <form id="searchForm" class="form-panel" action="/rest/manage/joinus/loadData">
      <ul class="panel-content">
          <li>
              <div class="form-actions">
                  <div class="control-group controls span5">
                      <input type="text" id="searchForm" class="input-normal  input-pad cartNo" name="name">
                  </div>
                  <div class="form-actions  controls">
                      <button type="submit" class="button  button-success">
                          查询
                      </button>
                      <a  class="button button-danger" onclick="return delFunction();">
                          <i class="icon-remove-sign icon-white"></i> 批量删除
                      </a>
                  </div>

              </div>
          </li>
      </ul>
  </form>
    <div id="grid"></div>
<div id="editContent" style="display:none;">
    <form id="editForm" class="form-horizontal" >
        <input type="hidden" name="id">
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">   <s>*</s>客户名称：</label>
                <div class="control-group-img  controls ">
                    <input type="text" class="input-normal control-text" name="name" readonly>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">   <s>*</s>联系电话：</label>
                <div class="control-group-img  controls ">
                    <input type="number" class="input-normal control-text" name="phone" readonly>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">   <s>*</s>所在区域：</label>
                <div class="control-group-img  controls ">
                    <input type="text" class="input-normal control-text" name="address" readonly>
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title : '序号', dataIndex :'id',elCls: 'center', width:'20%',renderer:function (value, obj, index) {
                        return index+1;
                    }},
                {title : '客户名称',dataIndex :'name', elCls: 'center', width:'20%'},
                {title : '电话',dataIndex :'phone', elCls: 'center', width:'20%'},
                {title : '所在地区',dataIndex :'address', elCls: 'center', width:'20%'},
                {title : '操作',dataIndex : 'id',elCls: 'center', width:'20%',renderer : function (value,obj,index) {
                        return '<a href="javascript:editById(' + value + ')">查看</a>'
                                +'&nbsp;&nbsp;<a href="javascript:deleteOne(' + value + ')">删除</a>';
                    }
                }
            ];

    var store = new Store({
                url : '/rest/manage/joinus/loadData',
                autoLoad:true, //自动加载数据
                params : { //配置初始请求的参数
                    length : '10',
                    status:$("#status").val()
                },
                pageSize:10,	// 配置分页数目
                root : 'list',
                totalProperty : 'total'
            }),
            grid = new Grid.Grid({
                render:'#grid',
                columns : columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar:{
                    pagingBar:true
                }
            });

    grid.render();

    function delFunction(){
        var selections = grid.getSelection();
        var ids=new Array();
        for(var i=0;i<selections.length;i++){
            ids[i]=selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/rest/manage/joinus/deletesJson",
            dataType: "json",
            data: {
                ids:ids
            },
            success: function (data) {
                var obj = new Object();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });
    }
    function deleteOne(id) {
        BUI.Message.Confirm('确认要删除吗？', function () {
            $.ajax({
                type: "POST",
                url: "${basepath}/rest/manage/joinus/deleteJson",
                dataType: "json",
                data: {
                    id: id
                },
                success: function (data) {
                    var obj = form.serializeToObject();
                    obj.start = 0;
                    store.load(obj);
                }
            });
        },'question')
    }
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    var editForm = new BUI.Form.Form;
    editForm.render();

    var editDialog = new BUI.Overlay.Dialog({
        title: '查询客户',
        width: 450,
        height: 250,
        buttons:[],
        contentId: 'editContent',
        success: function () {
            if (editForm.isValid()) {
                editForm.submit();
            } else {
                editForm.valid();
            }
        }
    });

    //编辑按钮事件
    function editById(id) {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "${basepath}/rest/manage/joinus/toEditJson",
            data: {id: id},
            success: function (data) {
                var form = $("#editForm")[0];
                BUI.FormHelper.setFields(form, data.data);
                editDialog.show();
            }
        });
    }
</script>

</@page.pageBase>
